define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'spell/returned/index' + location.search,
                    add_url: 'spell/returned/add',
                    edit_url: 'spell/returned/edit',
                    multi_url: 'spell/returned/multi',
                    table: 'spell_returned',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'orderId', title: __('Orderid')},
                        {field: 'goodsName', title: __('Goodsname')},
                        {field: 'skuName', title: __('Skuname')},
                        {field: 'goodsPrice', title: __('Goodsprice'), operate:'BETWEEN'},
                        {field: 'returnPrice', title: __('Returnprice'), operate:'BETWEEN'},
                        {field: 'applyModel', title: __('Applymodel'), formatter: Table.api.formatter.status,searchList: {"1":"退货退款","2":"退钱"}},
                        {field: 'orderStatus', title: __('Orderstatus'), formatter: Table.api.formatter.status,searchList: {"0":"未选择","1":"未收货","2":"已收货"}},
                        {field: 'applyInfo', title: __('Applyinfo')},
                        {field: 'info', title: __('Info')},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'expressName', title: '快递'},
                        {field: 'expressNo', title: '单号'},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status,searchList: {"1":"申请中","2":"已同意","3":"待补全","4":"已补全","6":"已拒绝","9":"已撤销","10":"已删除"}},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
